package com.example.theoretical_verification.collection;

import java.util.Objects;

public class Student01 {
    String name;
    int age;

    public Student01(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) { // o表示集合里面已有的某一个元素
        // == 比较的是对象内存地址
        if (this == o) return true; // this表示的是本次要加入的元素
        if (o == null || getClass() != o.getClass()) return false;
        Student01 student = (Student01) o;  //把o强制转型
        return age == student.age && Objects.equals(name, student.name); //age其实就是this.age，省略了this。name也是this.name，省略了this。

    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}' +'\n';
    }


}
